
import React from 'react'

import { Router, Route, Switch } from 'react-router-dom'
import Login from '@/pages/Login/Login.jsx'
import Home from '@/pages/Layout/Layout.jsx'
import NotFound from '@/pages/NotFound/NotFound.jsx'
// import { hasToken } from './utils/storage'
// import { Redirect } from 'react-router-dom'
import PrivateRoute from './components/PrivateRoute'
import { history } from './utils/history'


function App () {
  return (
    <div className='app'>
      <Router history={history}>
        <Switch>
          <Route exact path='/login' component={Login}></Route>
          {/* <Route path='/home' component={Home}></Route> */}

          {/* 实现访问控制，初级使用如下 */}
          {/* <Route path='/home' render={()=>{
            const token =  hasToken()
            if(token) return <Home/>
            return <Redirect to="/login"></Redirect>
          }}></Route> */}
          {/* 封装 PrivateRoute 组件 ，实现访问控制 */}
          <PrivateRoute path="/home" component={Home}></PrivateRoute>

          <Route component={NotFound}></Route>
        </Switch>
      </Router>
    </div>
  )
}

export default App
